package com.example.usercount.service.imply;


import com.example.usercount.dao.UserDAO;
import com.example.usercount.entity.UserEntity;
import com.example.usercount.service.UserService;
import com.example.vo.UserVIO;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.validation.constraints.NotNull;

@Service("UserService")
public class UserServiceImply implements UserService {

    @Autowired
    UserDAO userDAO;
    @Override
    public UserVIO getUserCountdetails(Long userID) {
        UserEntity userEntity = userDAO.getUserCountdetails(userID);
        UserVIO userVIO = new UserVIO();
        if(null!=userEntity){
            BeanUtils.copyProperties(userEntity,userVIO);
        }else{
            return null;
        }
        return userVIO;
    }
    @GlobalTransactional
    @Transactional
    @Override
    public boolean cutmoneyByUserId(@NotNull UserVIO userVIO) {
        System.out.println(userVIO);
        if(null == userVIO.getCutMoney()){
            return false;
        }
        int r = userDAO.cutmoneyByUserId(userVIO);
        return r==1?true:false;
    }
}
